using SqlSugar;
using IM.Easy.Core.Services;
using IM.Easy.Core.Utils;
using IM.Easy.Infrastructure.Query;
using IM.Easy.Core.Extensions;
using IM.Easy.Entity.System;
using IM.Easy.SystemServices.Dtos;
using IM.Easy.SystemServices.IServices;

namespace IM.Easy.SystemServices.Services
{
    public class NotificationService : AppServices, INotificationService
    {

        public NotificationService(ISqlSugarClient db) : base(db)
        {

        }

        public SysNotification Create(SysNotification entity)
        {
            // TODO: 添加创建逻辑
            return Db.Insertable(entity).ExecuteReturnEntity();
        }

        public SysNotification GetById(long id)
        {
            // TODO: 添加获取逻辑
            return Db.Queryable<SysNotification>().InSingle(id);
        }
        
        public PageResponse<SysNotification> GetPageList(SysNotificationQueryDto query)
        {
            var queryable = Db.Queryable<SysNotification>();
            var exp = Expressionable.Create<SysNotification>();
            exp = exp
                  .AndIF(!string.IsNullOrEmpty(query.Title), s => s.Title.Contains(query.Title))
                  .AndIF(query.Priority != default, s => s.Priority == query.Priority)
                  .AndIF(query.Status != default, s => s.Status == query.Status)
;
            var page = queryable
                 .Where(exp.ToExpression())
                 .ToPageList<SysNotification,SysNotification>(query);
             return page;
        }

        public bool Update(SysNotification entity)
        {
            // TODO: 添加更新逻辑
            return Db.Updateable(entity).ExecuteCommandHasChange();
        }

        public bool Delete(params long[] Id)
        {
            // TODO: 添加删除逻辑
            return Db.Deleteable<SysNotification>(Id).ExecuteCommandHasChange();
        }
    }
}
